package com.ktgj.flight.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.FlightCabinrule;
import com.ktgj.flight.service.IFlightCabinruleService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 机票舱位退改签规则Controller
 * 
 * @author ruoyi
 * @date 2022-04-18
 */
@RestController
@RequestMapping("/flightCabinrule")
public class FlightCabinruleController extends BaseController
{
    @Autowired
    private IFlightCabinruleService flightCabinruleService;

    /**
     * 查询机票舱位退改签规则列表
     */
    @PreAuthorize(hasPermi = "flight:cabinrule:list")
    @GetMapping("/list")
    public TableDataInfo list(FlightCabinrule flightCabinrule)
    {
        startPage();
        List<FlightCabinrule> list = flightCabinruleService.selectFlightCabinruleList(flightCabinrule);
        return getDataTable(list);
    }

    /**
     * 导出机票舱位退改签规则列表
     */
    @PreAuthorize(hasPermi = "flight:cabinrule:export")
    @Log(title = "机票舱位退改签规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlightCabinrule flightCabinrule) throws IOException
    {
        List<FlightCabinrule> list = flightCabinruleService.selectFlightCabinruleList(flightCabinrule);
        ExcelUtil<FlightCabinrule> util = new ExcelUtil<FlightCabinrule>(FlightCabinrule.class);
        util.exportExcel(response, list, "机票舱位退改签规则数据");
    }

    /**
     * 获取机票舱位退改签规则详细信息
     */
    @PreAuthorize(hasPermi = "flight:cabinrule:query")
    @GetMapping(value = "/{ruleid}")
    public AjaxResult getInfo(@PathVariable("ruleid") Long ruleid)
    {
        return AjaxResult.success(flightCabinruleService.selectFlightCabinruleById(ruleid));
    }

    /**
     * 新增机票舱位退改签规则
     */
    @PreAuthorize(hasPermi = "flight:cabinrule:add")
    @Log(title = "机票舱位退改签规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlightCabinrule flightCabinrule)
    {
        return toAjax(flightCabinruleService.insertFlightCabinrule(flightCabinrule));
    }

    /**
     * 修改机票舱位退改签规则
     */
    @PreAuthorize(hasPermi = "flight:cabinrule:edit")
    @Log(title = "机票舱位退改签规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlightCabinrule flightCabinrule)
    {
        return toAjax(flightCabinruleService.updateFlightCabinrule(flightCabinrule));
    }

    /**
     * 删除机票舱位退改签规则
     */
    @PreAuthorize(hasPermi = "flight:cabinrule:remove")
    @Log(title = "机票舱位退改签规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ruleids}")
    public AjaxResult remove(@PathVariable Long[] ruleids)
    {
        return toAjax(flightCabinruleService.deleteFlightCabinruleByIds(ruleids));
    }
}
